//
//  NSURL+AZURLRouter.m
//  AZRouter
//
//  Created by GorXion on 2018/4/4.
//  Copyright © 2018年 gaoX. All rights reserved.
//

#import "NSURL+AZURLRouter.h"

@implementation NSURL (AZURLRouter)

- (NSURL *)replacingPath:(NSString *)path
{
    NSString *URLString = self.absoluteString;
    NSString *resultURLString = [URLString stringByReplacingCharactersInRange:[URLString rangeOfString:self.path] withString:path];
    return [NSURL URLWithString:resultURLString];
}

- (NSDictionary *)parameters
{
    NSArray *querys = [self.query componentsSeparatedByString:@"&"];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    for (NSString *item in querys) {
        NSArray *params = [item componentsSeparatedByString:@"="];
        if (params.count > 1) [parameters setObject:params.lastObject forKey:params.firstObject];
    }
    return parameters.copy;
}

@end
